package com.tian.controller;

import com.tian.dto.PayNotifyTestReqDto;
import com.tian.service.NotifyPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * {@code @description:} TODO
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2025-01-20 9:54
 * {@code @version:} 1.0
 */
@Slf4j
@RestController
@RequestMapping("/pay/prepay")
public class PayNotifyController {

    @Resource
    private NotifyPayService notifyPayService;

    @PostMapping("/notify")
    public ResponseEntity payNotify(HttpServletRequest request) {
        try {
            return notifyPayService.payNotify(request, null);
        } catch (Exception e) {
            log.error("预支付接口异常", e);
            return new ResponseEntity<>("failed", HttpStatus.EXPECTATION_FAILED);
        }
    }

    /**
     * 模拟 支付回调通知 接口
     */
    @PostMapping("/notify/test")
    public ResponseEntity payNotifyTest(@RequestBody PayNotifyTestReqDto payNotifyTestReqDto) {
        try {
            return notifyPayService.payNotify(null, payNotifyTestReqDto);
        } catch (Exception e) {
            log.error("预支付接口异常", e);
            return new ResponseEntity<>("failed", HttpStatus.EXPECTATION_FAILED);
        }
    }
}
